import { useEffect } from "react";
import { useReactive } from "ahooks";
import taskScene from "../../public/todo_task_roles.json";

export default function taskModal() {
    const state = useReactive({
        taskInfo: {},
        taskUuid: null,
        rightSiderWidth: 100,
        taskScene,
    });

    const setRightSiderWidth = (width) => (state.rightSiderWidth = width);

    useEffect(() => {
        let urlObj = new URL(window.location.href);
        let taUuid = urlObj.searchParams.get("taUuid");
        if (taUuid) state.taskUuid = taUuid;
    }, []);

    const setTaskUuid = (taskUuid) => (state.taskUuid = taskUuid);
    const setTaskInfo = (taskInfo) => (state.taskInfo = taskInfo);
    const setTaskScene = (taskScene) => (state.taskScene = taskScene);

    return {
        ...state,
        setTaskUuid,
        setTaskInfo,
        setRightSiderWidth,
        setTaskScene,
    };
}
